import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { DelDataButton, ExecuteButton } from '../Common/options'
import { TunnelInfos } from '../Common/Conversion'

export const TunnelGase = async ({ url, OptionsEvent, Permission, actionRef }) => {
    let data = {
        type: '隧道管理',
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'createTime@desc' },
        get: API_LIST()[`get${url}OC`],
        modify: `put${url}`,
        delete: `del${url}`,
        columns: [
            commonTableList.uuid,
            { ...commonTableList.code, rules: true, hideInSearch: false },
            {
                dataIndex: 'tunnelInfoUuid',
                title: '隧道',
                valueType: 'select',
                valueEnum: await TunnelInfos(),
                rules: true,
                width: 100,
                hideInSearch: false,
            },
            {
                dataIndex: 'lorR',
                key: 'TunnelLorR',
                title: '部位',
                valueType: 'select',
                valueEnum: BuiltInData.lorR,
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'gasName',
                title: '气体名称',
                valueType: 'input',
                valueEnum: {},
                rules: true,
                width: 150,
                hideInSearch: false,
            },
            {
                dataIndex: 'deviceName',
                title: '采集气体设备名',
                valueType: 'select',
                valueEnum: {},
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'gasValue',
                title: '气体数据',
                valueType: 'select',
                valueEnum: {},
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'gasUnit',
                title: '数据单位',
                valueType: 'select',
                valueEnum: {},
                rules: true,
                width: 100,
                hideInSearch: true,
            },

            {
                dataIndex: 'alarm',
                title: '报警标志',
                valueType: 'select',
                valueEnum: BuiltInData.alarm,
                rules: true,
                width: 100,
                hideInSearch: false,
            },
            {
                ...commonTableList.isEnabled,
                title: '报警状态',
                hideInSearch: false,
                valueEnum: BuiltInData.status,
            },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            commonTableList.StartTime,
            commonTableList.EndTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, alarm, isEnabled } = record
                    return [
                        alarm === 1 && isEnabled === 0 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="one"
                                title="解除报警"
                                url="posTunnelGaseUpdateIsEnabled"
                                path={[uuid]}
                                tips="已处置报警信息!"
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '35262d46-62d0-45e2-8aa6-03419975307e') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
